package com.huicheng.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

import com.huicheng.App;

/**
 * Created by lk on 2018/3/3.
 */

public class SharedPreUtils {
    private static SharedPreUtils instance;
    private SharedPreferences sharedPreferences;
    public SharedPreUtils() {
        sharedPreferences = App.context.getSharedPreferences("config", Context.MODE_PRIVATE);
    }

    public static SharedPreUtils getInstance(){
        if (instance ==null){
            synchronized (SharedPreUtils.class){
                if (instance ==null){
                    instance = new SharedPreUtils();
                }
            }
        }
        return instance;
    }

    public void putSting(String key,String value){
        if (TextUtils.isEmpty(key) || TextUtils.isEmpty(value)){
            return;
        }
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(key,value);
        editor.commit();
    }
    public String getString(String key){
        if (sharedPreferences!=null){
            return sharedPreferences.getString(key,null);
        }
        return null;
    }
    public void removeString(String key){
        if (TextUtils.isEmpty(key)){
            return;
        }
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.remove(key);
        editor.commit();
    }
}
